<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>学生登记</title>
	<meta name="decorator" content="ani"/>
	<style>
		.select-disabled {
			pointer-events: none;
			background-color: #eeeeee;
		}
	</style>
	<script type="text/javascript">

		$(document).ready(function() {

			$("#inputForm").find("select").each(function () {
				if ($(this).attr("data-value") != '' && $(this).attr("data-value") != undefined) {
					$(this).val($(this).attr("data-value"));
				}
			});
			jp.ajaxForm("#inputForm",function(data){
				if(data.success){
				    jp.success(data.msg);
					jp.go("${ctx}/buzz/student/student");
				}else{
				    jp.error(data.msg);
				    $("#inputForm").find("button:submit").button("reset");
				}
			});

		});

		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD HH:mm:ss"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}


		function selectRow() {
			top.layer.open({
			type: 2,
			//shade:0,
			area: ['1300px', '1000px'],
			title:"选择",
			auto:true,
			maxmin: true, //开启最大化最小化按钮
			content: "${ctx}/buzz/student/student/outSelect",
			btn: ['确定', '关闭'],
				yes: function(index, layero){
					var ids = layero.find("iframe")[0].contentWindow.getIdSelections();
					var data = layero.find("iframe")[0].contentWindow.getSelections();
					if(ids.length ==0){
						jp.warning("请选择至少一个数据!");
						return;
					}
					// 执行保存
					for(var i = 0;i<data.length; i++){
						addRow('#studententryList', studententryRowIdx, studententryTpl,data[i]);
						studententryRowIdx = studententryRowIdx + 1;
					}
					top.layer.close(index);
				},
				cancel: function(index){
					//取消默认为空，如需要请自行扩展。
					top.layer.close(index);
				}
			});
		}
	</script>
</head>
<body>
<div class="wrapper wrapper-content">
	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-primary">
				<div class="panel-heading">
					<h3 class="panel-title">
						<a class="panelButton" href="${ctx}/buzz/student/student"><i class="ti-angle-left"></i> 返回</a>
					</h3>
				</div>
				<div class="panel-body">
					<form:form id="inputForm" modelAttribute="student" action="${ctx}/buzz/student/student/save" method="post" class="form-horizontal">
						<form:hidden path="id"/>
						<form:hidden path="classid"/>
						<form:hidden path="company.id"/>
							<fieldset class="well-new">
								<legend><i style="padding: 0px 5px 0px 5px" aria-hidden="true"></i>基本信息</legend>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">学生姓名：</label>
									<div class="col-sm-10 col-md-2">
										<form:input path="name" htmlEscape="false"    class="form-control "/>
									</div>
									<label class="col-sm-2 col-md-1 control-label">性别：</label>
									<div class="col-sm-10 col-md-2">
										<form:select path="sex" class="form-control " data-value="${student.sex}">
											<form:option value="" label=""/>
											<form:options items="${fns:getDictList('Sys_XingBie')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
										</form:select>
									</div>
									<label class="col-sm-2 col-md-1 control-label">就读学校：</label>
									<div class="col-sm-10 col-md-2">
										<select id="schoo" name="schoo.id" class="form-control m-b required" data-value="${student.schoo.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|学校名称' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
									<label class="col-sm-2 col-md-1 control-label">就读年级：</label>
									<div class="col-sm-10 col-md-2">
										<select id="grade" name="grade.id" class="form-control m-b required" data-value="${student.grade.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|就读年级' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">就读班级：</label>
									<div class="col-sm-10 col-md-2">
										<select id="banji" name="banji.id" class="form-control m-b required" data-value="${student.banji.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|班级就读' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
									<label class="col-sm-2 col-md-1 control-label">班干：</label>
									<div class="col-sm-10 col-md-2">
										<select id="bangan" name="bangan.id" class="form-control m-b required" data-value="${student.bangan.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|班干分类' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
									<label class="col-sm-2 col-md-1 control-label">学号：</label>
									<div class="col-sm-10 col-md-2">
										<form:input path="xuehao" htmlEscape="false"    class="form-control "/>
									</div>
									<label class="col-sm-2 col-md-1 control-label">证件号：</label>
									<div class="col-sm-10 col-md-2">
										<form:input path="card" htmlEscape="false"    class="form-control "/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">教室名称：</label>
									<div class="col-sm-10 col-md-2">
										<select id="room" name="room.id" class="form-control m-b required" data-value="${student.room.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|教室管理' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">过敏备注：</label>
									<div class="col-sm-10 col-md-11">
										<form:textarea path="guominbeizhu" htmlEscape="false" rows="4"    class="form-control "/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">病史备注：</label>
									<div class="col-sm-10 col-md-11">
										<form:textarea path="bingshibeizhu" htmlEscape="false" rows="4"    class="form-control "/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">心愿备注：</label>
									<div class="col-sm-10 col-md-11">
										<form:textarea path="xinyuanbeizhu" htmlEscape="false" rows="4"    class="form-control "/>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">备注：</label>
									<div class="col-sm-10 col-md-11">
										<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>
									</div>
								</div>
							</fieldset>
							<fieldset class="well-new">
								<legend><i style="padding: 0px 5px 0px 5px" aria-hidden="true"></i>家长</legend>
									<div class="tabs-container">
										<div class="tab-content">
											<div id="tab-1" class="tab-pane fade in  active" style="overflow-x: scroll;height: 350px">
												<a class="btn btn-white btn-sm" onclick="selectRow()" title="添加"><i class="fa fa-plus"></i> 家长选择</a>
												<table class="table table-striped table-bordered table-condensed  text-nowrap">
													<thead>
													<tr>
														<th class="hide"></th>
														<th>操作</th>
														<th style="min-width:100px"><font color="red">家长</font></th>
														<th style="min-width:100px"><font color="red">关系</font></th>
														<th style="min-width:600px">备注</th>
													</tr>
													</thead>
													<tbody id="studententryList">
													</tbody>
												</table>
												<script type="text/template" id="studententryTpl">//<!--
													<tr id="studententryList{{idx}}">
														<td class="hide">
															<input id="studententryList{{idx}}_id" 				name="studententryList[{{idx}}].id" 					type="hidden" value="{{row.id}}"/>
															<input id="studententryList{{idx}}_delFlag" 		name="studententryList[{{idx}}].delFlag" 				type="hidden" value="0"/>
														</td>
														<td class="text-center" width="10">
															{{#delBtn}}<span class="close" onclick="delRow(this, '#studententryList{{idx}}')" title="删除">&times;</span>{{/delBtn}}

														</td>
														<td>
															<input id="studententryList{{idx}}_family" 			name="studententryList[{{idx}}].family.id" 				type="hidden" 		value="{{row.family.id}}"    class="form-control "/>
															<input id="studententryList{{idx}}_familyname" 		name="studententryList[{{idx}}].family.name" 			readonly="true"		value="{{row.family.name}}"    class="form-control "/>
														</td>
														<td style="min-width:100px">
															<sys:gridselect url="${ctx}/basedata/qinshuguanxi/qinshuguanxi/data"
																id="studententryList{{idx}}_qinshuguanxi"
																name="studententryList[{{idx}}].qinshuguanxi.id" 		value="{{row.qinshuguanxi.id}}"
																labelName="studententryList{{idx}}.qinshuguanxi.name" 	labelValue="{{row.qinshuguanxi.name}}"
																title="选择亲属关系" cssClass="form-control"
																fieldLabels="名称"
																fieldKeys="name"
																searchLabels="名称"
																searchKeys="name" cssStyle="width:280px">
															</sys:gridselect>
														</td>



														<td>
															<input id="studententryList{{idx}}_remarks" 		name="studententryList[{{idx}}].remarks" 								   	value="{{row.remarks}}" 	 class="form-control "/>
														</td>
													</tr>//-->
												</script>
												<script type="text/javascript">
													var studententryRowIdx = 0, studententryTpl = $("#studententryTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
													$(document).ready(function() {
														var data = ${fns:toJson(student.studententryList)};
														for (var i=0; i<data.length; i++){
															addRow('#studententryList', studententryRowIdx, studententryTpl, data[i]);
															studententryRowIdx = studententryRowIdx + 1;
														}
													});
												</script>
											</div>
										</div>
									</div>
							</fieldset>
						<c:if test="${mode == 'add' || mode=='edit'}">
							<div class="col-lg-3"></div>
							<div class="col-lg-6">
								<div class="form-group text-center">
									<div>
										<button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
									</div>
								</div>
							</div>
						</c:if>
						</form:form>
				</div>
			</div>
		</div>
	</div>
</div>
</body>

